// pages/allocation/allocation.js
const app = getApp()
import http from "../../utils/http"
import util from "../../utils/util"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: '',
    skill_id:'',
    popupOrder:false,
    list:[],
    finish: false,
    loading: false,
    page: 1,
    order: [],
    safeBottom: `30px`,
  },
  sure(){
    if(this.data.skill_id === '') return util.toast('请先选择服务者')
    http.get('shop/allocationorder', {
      id: this.data.id,
      skill_id: this.data.skill_id
    }, true, false).then(res => {
      util.toast('分配成功')
      setTimeout(()=>{
        util.back()
      },1000)
    }).catch(e => {
      let data = e.data
      if(data.code === 2){
        util.toast(data.msg)
        setTimeout(()=>{
          util.skip('/service/earnestMoney/earnestMoney')
        },1000)
      }else if(data.code === 0){
        util.toast(data.msg)
      }
    })
  },
  
  getList(){
    
    let data = {
      page: this.data.page,
      id: this.data.id
    }
    http.get('shop/getshopskill', data).then(res => {
   
      let arr = this.data.list.concat(res.data)
      this.setData({
        list: arr,
        finish: true
      })
      
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const high = app.globalData.safeBottom
    this.setData({
      safeBottom: `${high}px`,
      id: options.id
    })
    this.getList()
  },
  //查看订单
  examineOrder(e){
    this.setData({
      order: e.currentTarget.dataset.order,
      popupOrder:true
    })
  },
  closePop(){
    this.setData({
      popupOrder:false
    })
  },
  //切换
  select(e){
    this.setData({
      skill_id:e.currentTarget.dataset.id
    })
  },
  onClose() {
    this.setData({ popupOrder: false });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})